package com.httpclient;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;

/***
 * apache httpclient4.1 之后的版本设置 http 连接池
 */



public class SpiderHttpClientManager {
	 
	
	private SpiderHttpClientManager(){}
	
	private static HttpClient httpclient;
	
	public static HttpClient getInstance(){
		synchronized (SpiderHttpClientManager.class) {
			if(httpclient== null){
				MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
				HttpConnectionManagerParams pams = new HttpConnectionManagerParams();
				pams.setConnectionTimeout(100);
				pams.setDefaultMaxConnectionsPerHost(100);
				connectionManager.setParams(pams);
				httpclient = new HttpClient(connectionManager);
			}
		}
		return httpclient;
	}
}  
